//
//  AboutUsViewController.m
//  bleDemo
//
//  Created by wurz on 15/4/12.
//  Copyright (c) 2015年 wurz. All rights reserved.
//

#import "AboutUsViewController.h"

@interface AboutUsViewController ()
{
    UITableView *_tableView;
    
    NSMutableArray *_tableGroupData;//[分组1，分组2[one,two{key:value}]]
}

@end

@implementation AboutUsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.edgesForExtendedLayout = UIRectEdgeNone;
    
    self.extendedLayoutIncludesOpaqueBars = NO;
    self.modalPresentationCapturesStatusBarAppearance = NO;
    
    //设置背景颜色
    [self.view setBackgroundColor:[UIColor colorWithRed:239/255.0 green:236/255.0 blue:237/255.0 alpha:1.0]];
    
    //创建tableView
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
    
    //设置tableView的背景颜色为透明的
    [_tableView setBackgroundColor:[UIColor clearColor]];
    
    //实现tablewView的代理
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    //将tableView 添加到视图中
    [self.view addSubview:_tableView];
    
    //tableView中的数据
    _tableGroupData = [[NSMutableArray alloc] init];
    
    //获取版本号
//    NSString *appVersion = [NSString stringWithFormat:@"%@",[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]];
    
    //第一组信息
    NSArray *array = @[@{@"HJ-580 BLE":@"蓝牙APP"},@{@"公司":@"唐山宏佳电子科技有限公司"}];
    [_tableGroupData addObject:array];
    
    //第二组信息
    array = @[@{@"网址":@"www.tshjdz.com"}];
    [_tableGroupData addObject:array];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -- UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    //返回分组数
    return _tableGroupData.count;
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    //返回改分组数下面的行数
    NSArray *array = _tableGroupData[section];
    return array.count;
}


-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentify = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentify];
    //当tableview中没有cell时，创建
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentify];
        
        cell.textLabel.font = [UIFont systemFontOfSize:14.0];
        cell.detailTextLabel.font = [UIFont systemFontOfSize:14.0];
    }
    
    NSDictionary *dict = _tableGroupData[indexPath.section][indexPath.row];
    cell.textLabel.text = dict.allKeys[0];
    cell.detailTextLabel.text = dict.allValues[0];
    
    if ([dict.allKeys[0] isEqualToString:@"网址"]) {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    
    return cell;
}

#pragma mark -- UITableViewDelegete
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //点击后取消选中状态
    [_tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    NSDictionary *dict = _tableGroupData[indexPath.section][indexPath.row];
    if ([dict.allKeys[0] isEqualToString:@"网址"]) {
        NSString *web = [NSString stringWithFormat:@"http://%@",dict.allValues[0]];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:web]];
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
